<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>流程业务配置</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/adminui/dist/css/admin.css}" media="all">
  <link rel="stylesheet" th:href="@{/style/custom.css}" media="all">
</head>
<body>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto layui-form-pane" lay-filter="LAY-biz-config-front-form">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">流程定义</label>
          <div class="layui-input-block">
            <select name="procDefKey" id="procDefKey" lay-search>
              <option value="">全部</option>
              <option th:each="obj:${defKeys}" th:value="${obj.key}" th:text="${obj.value}"></option>
            </select>
          </div>
        </div>
        <div class="layui-inline">
          <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="LAY-biz-config-front-search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 搜索
          </button>
          <button class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="LAY-biz-config-front-reset">
            <i class="layui-icon layui-icon-refresh layuiadmin-button-btn"></i> 重置
          </button>
        </div>
      </div>
    </div>

    <div class="layui-card-body">
      <div class="layui-btn-group" style="padding-bottom: 10px;">
        <!--刷新table-->
        <button type="button" class="layui-btn layui-btn-normal btn-op-biz-config layui-btn-sm" data-type="refresh">
          <i class="layui-icon">&#xe666;</i>刷新
        </button>
        <!-- 新增 -->
        <button type="button" class="layui-btn layui-btn-normal btn-op-biz-config layui-btn-sm" data-type="add">
          <i class="layui-icon">&#xe654;</i>新增
        </button>
        <!-- 修改 -->
        <button type="button" class="layui-btn layui-btn-normal btn-op-biz-config layui-btn-sm" data-type="edit">
          <i class="layui-icon layui-icon-edit"></i>修改
        </button>
        <!-- 删除 -->
        <button type="button" class="layui-btn layui-btn-danger btn-op-biz-config layui-btn-sm" data-type="del">
          <i class="layui-icon layui-icon-delete"></i>删除
        </button>
      </div>

      <!--table 定义-->
      <table id="LAY-biz-config-table" lay-filter="LAY-biz-config-table"></table>

      <!--列表操作项-->
<!--      <script type="text/html" id="biz-config-table">-->
<!--        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>-->
<!--        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
<!--      </script>-->
    </div>
  </div>
</div>

<script th:src="@{/layui/layui.js}"></script>
<script>
  layui.config({
    base: '/'
  }).extend({
    //设定模块别名，模块名是使用layui.模块名  模块文件是 js名字。不设置模块名 = 模块文件名
    bizConfig: 'modules/process/bizConfig/index'
  }).use(['bizConfig'], function() {
    let form = layui.form;
    let admin = layui.admin;
    let table = layui.table;
    let upload = layui.upload;

    //监听搜索
    layui.form.on('submit(LAY-biz-config-front-search)', function (data) {
      let field = data.field;
      //执行重载
      layui.table.reload('LAY-biz-config-table', {
        where: field
      });
    });
    // 监听重置
    layui.form.on('submit(LAY-biz-config-front-reset)', function (data) {
      let field = data.field;
      for (let key of Object.keys(field)) {
        field[key] = '';
      }
      layui.form.val("LAY-biz-config-front-form", field);
    });


    //事件
    let active = {
      add: function () {
        layer.open({
          type: 2
          , title: '新增'
          , content: '/process/bizConfig/edit'
          // ,maxmin: true
          , resize: false
          , area: ['500px', '540px']
          , btn: ['确定', '取消']
          , yes: function (index, layero) {
            let iframeWindow = window['layui-layer-iframe' + index]
                , submitID = 'LAY-biz-config-front-submit'
                , submit = layero.find('iframe').contents().find('#' + submitID);

            //监听提交
            iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
              let field = data.field; //获取提交的字段
              let bizName = layero.find('iframe').contents().find('#bizCode option:selected').text();
              field.bizName = bizName;

              //提交 Ajax 成功后，更新表格中的数据
              admin.req({
                url: '/process/bizConfig/save'
                , type: 'post'
                , contentType: 'application/json;charset=utf-8'
                , data: JSON.stringify(field)
                , done: function (res) {
                  //执行成功
                  layer.msg(res.msg, {icon: 1});
                  table.reload('LAY-biz-config-table'); //数据刷新
                  layer.close(index); //关闭弹层
                }
              });
            });

            submit.trigger('click');
          }
          , success: function (layero, index) {

          }
        });
      }
      , edit: function () {
        let checkData = table.checkStatus('LAY-biz-config-table').data;
        if (!checkData || checkData.length != 1) {
          layer.msg('请选择一行记录操作！',{icon: 0});
          return;
        }
        layer.open({
          type: 2
          , title: '修改'
          , content: '/process/bizConfig/edit?id=' + checkData[0].id
          // ,maxmin: true
          , resize: false
          , area: ['500px', '540px']
          , btn: ['确定', '取消']
          , yes: function (index, layero) {
            let iframeWindow = window['layui-layer-iframe' + index]
                , submitID = 'LAY-biz-config-front-submit'
                , submit = layero.find('iframe').contents().find('#' + submitID);

            //监听提交
            iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
              let field = data.field; //获取提交的字段
              let bizName = layero.find('iframe').contents().find('#bizCode option:selected').text();
              field.bizName = bizName;

              //提交 Ajax 成功后，更新表格中的数据
              admin.req({
                url: '/process/bizConfig/save'
                , type: 'post'
                , contentType: 'application/json;charset=utf-8'
                , data: JSON.stringify(field)
                , done: function (res) {
                  //执行成功
                  layer.msg(res.msg, {icon: 1});
                  table.reload('LAY-biz-config-table'); //数据刷新
                  layer.close(index); //关闭弹层
                }
              });
            });

            submit.trigger('click');
          }
          , success: function (layero, index) {

          }
        });
      }
      , del: function () {
        let checkData = table.checkStatus('LAY-biz-config-table').data;
        if (!checkData || checkData.length != 1) {
          layer.msg('请选择一行记录操作！',{icon: 0});
          return;
        }
        layer.confirm('真的删除行么？', function (index) {
          //提交 Ajax 成功后，更新表格中的数据
          admin.req({
            url: '/process/bizConfig/del'
            , type: 'post'
            , contentType: 'application/json;charset=utf-8'
            , data: JSON.stringify({'id': checkData[0].id})
            , done: function (res) {
              //执行成功
              layer.msg(res.msg, {icon: 1});
              table.reload('LAY-biz-config-table'); //数据刷新
            }
          });
        });
      }
      , refresh: function () {
        let data = layui.form.val("LAY-biz-config-front-form");
        //执行重载 数据刷新
        layui.table.reload('LAY-biz-config-table', {
          where: data
        });
      }
    };

    //执行事件操作
    layui.$('.layui-btn.btn-op-biz-config').on('click', function () {
      let type = layui.$(this).data('type');
      active[type] ? active[type].call(this) : '';
    });


  });
</script>
</body>
</html>
